/**	
 * Title: CSE 5322 - Software Design Patterns
 * Description: 
 * Copyright: Copyright (c) UT Arlington, 2011
 * @author: Duy Nguyen(duyanh@uta.edu), Vivek Maheshwari(vivekm@uta.edu), Arjun Satish(arjun.satish@mavs.uta.edu), Lakshmana Srinivasa(lakshmana.srinivasa@mavs.uta.edu), Ismat Jahan(ismat.jahan@mavs.uta.edu)
 * @version 1.0
 */

package edu.uta.cse5322_2011_team3;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NLPUCParser implements UCParserImpl {

	public ArrayList<UseCase> identify(Document document) {
		ArrayList<UseCase> useCases = new ArrayList<UseCase>();
		
		ArrayList<String> sentences = document.toSentences();

		NLPParser parser = NLPParser.getInstance();

		for (String sentence : sentences) {
			String taggedSentence = parser.parse(NLPParser.normalizeRequirement(sentence));
			
//			System.out.println(taggedSentence);
			
			Pattern p = Pattern
					.compile("(\\w+)/NNP shall/MD allow/VB the/DT (\\w+)/NN to/TO (\\w+/VB) ([^\\.]+).");
			Matcher m = p.matcher(taggedSentence);
			while (m.find()) {
				UseCase uc = new UseCase();
				uc.setActor(new Actor(NLPParser.removeTags(m.group(2))));
				uc.setSystem(new UCSystem(NLPParser.removeTags(m.group(1))));
				uc.setName(NLPParser.removeTags(m.group(3) + " "
						+ NLPParser.removeTags(m.group(4))));
				useCases.add(uc);
				System.out.println(uc);
			}
		}
		return useCases;
	}
}
